package com.hc.commView;

import java.util.List;

import com.hc.bean.BaseStationBean;
import com.hc.util.CommonData;
import com.hc.util.ImageUtil;
import com.hc.window.BaseStationPanel;
import com.hc.window.MapPanel;

public class BaseStationManagement {
	
	public static void initBaseStationBean(List<BaseStationBean> beans){
		clearOld();
		
		for(BaseStationBean b : beans){
			CommonData.baseStationBeans.put(b.getId(), b);
		}
		
		initBaseStationView();
		updateShowPanel();
	}
	
	private static void updateShowPanel(){
		for (Object ob : CommonData.baseStationBeans.keySet()) {
			BaseStationBean bean = CommonData.baseStationBeans.get(ob);
			BaseStationPanel bp = new BaseStationPanel(bean);
			CommonData.baseStationPanels.put(bean.getId(), bp);
		}
	}
	
	private static void clearOld(){
		MapPanel.mapPanel.removeBaseAndView();
		CommonData.deviceBeans.clear();
		CommonData.DeviceViews.clear();
		CommonData.baseStationBeans.clear();
		CommonData.baseStationViews.clear();
		CommonData.baseStationPanels.clear();
		MapPanel.mapPanel.updateArea();
	}
	
	private static void initBaseStationView() {
		for (Integer id : CommonData.baseStationBeans.keySet()) {
			BaseStationBean bean = CommonData.baseStationBeans.get(id);
			BaseStationView bsv = null;
			if(CommonData.baseStationViews.containsKey(id)){
				bsv = CommonData.baseStationViews.get(id);
				bsv.setBean(CommonData.baseStationBeans.get(id));
			}else{
				bsv = new BaseStationView(ImageUtil.station0);
				bsv.setBean(bean);
				MapPanel.mapPanel.add(bsv);
				CommonData.baseStationViews.put(id, bsv);
			}
			bsv.refreshData();
			bsv.suoFang();
		}
	}
}
